package com.gintama;

import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

public class CASDemo {

    @Test
    public void demo1(){
        AtomicInteger atomicInteger = new AtomicInteger(5);
        atomicInteger.compareAndSet(5,2025);
        System.out.println(atomicInteger.get());
        atomicInteger.compareAndSet(5,2026);
        System.out.println(atomicInteger.get());
    }

    @Test
    public void demo2(){
        User user1 = new User("zhang",10);
        User user2 = new User("huang",12);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(user1);
        boolean compareAndSet = atomicReference.compareAndSet(user1, user2);
        System.out.println(compareAndSet);
        System.out.println(atomicReference.get().toString());
    }

    @Test
    public void demo(){
        int a = 1%3;
        System.out.println(a);
    }
}
